//
//  HICMainViewController.swift
//  vibo
//
//  Created by jht-seven on 16/6/25.
//  Copyright © 2016年 jht-seven. All rights reserved.
//

import UIKit

class HICMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //自定义tabbar
        let tabBar = HICTabBar()
        
        // 设置代理
        tabBar.hicDelegate = self
        
        setValue(tabBar, forKey: "tabBar")
        
        
        // 通过KVC 给只读属性赋值
        
        addChildViewController(HICHomeTableViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(HICMessageTableViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(HICDiscoverTableViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(HICProfileTableViewController(), title: "我", imgName: "tabbar_profile")
       
    }

    func addChildViewController(vc:UIViewController, title:String, imgName:String){
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imgName)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        let navC = UINavigationController(rootViewController: vc)
        addChildViewController(navC)
    }
}

extension HICMainViewController: HICTabBarDelegate{
    func composeButtonClick() {
        print("弹出控制器")
        let nav = UINavigationController(rootViewController: HICComposeViewController())
        presentViewController(nav, animated: true, completion: nil)
    }
}
